package BanyuanClub.Study.Day0309.锁相关;

public class Dog extends Thread{
        @Override
    public void run() {
        //同步锁
        synchronized (GuanTou.class) {
        if (GuanTou.rou > 0){
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            GuanTou.rou -= 1;
            System.out.println(this + "吃了块肉");
        }
        System.out.println("还剩" + GuanTou.rou + "块肉");
    }

    }

    public static void main(String[] args) {
        Dog d1 = new Dog();
        Dog d2 = new Dog();
        d1.start();
        d2.start();
    }
}
